import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

Window {
    id: window
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Item {
        id: root
        anchors.fill: parent

        //取别名
        property alias windowWidth: window.width


        //此时是动态绑定的
        //property int num: parent.width
        property int num: 88
        onNumChanged: {
            console.log(num)
        }

        property var obj
        function setObj(value) {
            obj = value
        }

        Component.onCompleted: {
            //这样赋值就不是动态绑定的
            num = window.width

            //设置万能类型
            setObj("你好")
            console.log(obj)
            setObj(100)
            console.log(obj)
            setObj({a:'你好', b: 100})
            console.log(JSON.stringify(obj))

            //修改别名,等于直接改他的值(窗口宽度)
            windowWidth = 300
        }

        //子元素
        Row {
            id: row
            Rectangle {
                id: rect1
                width: 100
                height: 100
                color: 'red'
            }
            Rectangle {
                id: rect2
                width: 100
                height: 100
                color: 'green'
            }

            Component.onCompleted: {
                var childs = row.children
                //数量只数常规能显示的控件
                console.log(childs.length)
                console.log(childs[0].width)
            }
        }
    }
}
